package com.scalar.chiptrack.adaptor.ikanos.utac;

import com.scalar.chiptrack.jobs.JobHandler;
import com.scalar.chiptrack.adaptor.AdaptorConstants;
import com.scalar.chiptrack.adaptor.AdaptorUtils;
import com.scalar.chiptrack.adaptor.InventoryLot;
import com.scalar.chiptrack.adaptor.TestLot;
import com.scalar.chiptrack.adaptor.AssemblyLot;
import com.scalar.chiptrack.adaptor.FabSortLot;
import com.scalar.chiptrack.adaptor.ShippedLot;
import com.scalar.chiptrack.adaptor.TestLotBinReport;
import com.scalar.chiptrack.adaptor.utac.UTACPOP3WipStatus;
import com.scalar.chiptrack.adaptor.utac.UTACShipStatus;
import com.scalar.chiptrack.adaptor.dao.AdaptorDAO;
import com.scalar.chiptrack.adaptor.dao.AdaptorRunInfo;
import com.scalar.chiptrack.adaptor.dao.AssemblyAdaptorDAO;
import com.scalar.chiptrack.adaptor.dao.TestAdaptorDAO;
import com.scalar.chiptrack.adaptor.dao.ShippedLotDAO;
import com.scalar.chiptrack.adaptor.dao.InventoryLotDAO;
import com.scalar.chiptrack.adaptor.dao.FabSortAdaptorDAO;
import com.scalar.chiptrack.utils.Logger;
import com.scalar.chiptrack.utils.StringUtils;
import com.scalar.chiptrack.db.DBTransaction;
import com.scalar.ScalarException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Iterator;
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import jxl.Workbook;
import jxl.Cell;
import jxl.Sheet;
import jxl.CellType;
import jxl.DateCell;

/**
 * User: ChandraSekhar
 * Date: Jul 15, 2008
 * Time: 3:35:18 PM
 */
public class UTACDataParser extends JobHandler implements AdaptorConstants
{
    private static Logger m_parserLogger    = null;
    private String m_dataOutputDir          = null;

    private HashMap m_assyWipDataMap        = new HashMap();
    private HashMap m_ftDataMap             = new HashMap();
    private HashMap m_dieBankDataMap        = new HashMap();
    private HashMap m_waferBankDataMap      = new HashMap();
    private HashMap m_sortDataMap           = new HashMap();
    private HashMap m_sortShipDataMap       = new HashMap();
    private HashMap m_preTestDataMap        = new HashMap();
    private HashMap m_eolDataMap            = new HashMap();
    private HashMap m_fgDataMap             = new HashMap();
    private HashMap m_fgShipDataMap         = new HashMap();


    public UTACDataParser() throws ScalarException
    {
        try
        {
            m_dataOutputDir = AdaptorUtils.getDataOutputDir( VENDOR_NAME_UTAC, WIP_TYPE_ASSEMBLY );
            AdaptorUtils.makeAllAdaptorDirs( m_dataOutputDir );
            m_parserLogger = AdaptorUtils.getDataParserLogger( m_dataOutputDir,VENDOR_NAME_UTAC );
            AssemblyAdaptorDAO.setLogger( m_parserLogger );   // All the DAOs and Parser should be logging into same file
            TestAdaptorDAO.setLogger( m_parserLogger);
            InventoryLotDAO.setLogger( m_parserLogger );
            FabSortAdaptorDAO.setLogger( m_parserLogger );
            ShippedLotDAO.setLogger( m_parserLogger );
            AdaptorUtils.setLogger( m_parserLogger );
        }
        catch (ScalarException se)
        {
            log("ERROR!! ERROR!! ERROR!! Exception while loading/creating UTAC output directory from database, Exception: " + se);
            throw se;
        }
    }
    /**
     *
     * @param args
     * @throws Exception
     */
    public static void main( String args[] ) throws Exception
    {
        try
        {
            new UTACDataParser().execute();
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    //Execute Method
   public void execute() throws Exception
   {
       AdaptorUtils.printHeader(VENDOR_NAME_UTAC, CONSTANT_PARSER );

       File doneDestDir = new File( m_dataOutputDir + "/done" );

       File wipDataoutDir = new File( m_dataOutputDir );

       File[] fileList = wipDataoutDir.listFiles();

       if ( ( fileList == null ) || ( fileList.length <= 3 ) )
       {
           log( "No file found in directory: " + wipDataoutDir );
           throw new ScalarException( "No file found in directory: " + wipDataoutDir + "----\n\n" );
       }

       DBTransaction dbTransaction = null;
       ArrayList successFileList   = new ArrayList();
       boolean success             = false;

       try
       {
           for ( int i = 0; i < fileList.length; i++ )
           {
               if ( fileList[i].isDirectory() == true )
               {
                   continue;
               }

               if ( ( fileList[i].getName() != null ) && ( fileList[i].getName().trim().indexOf( UTACPOP3Adaptor.FILE_NAME_DAILY_WIP ) != -1 ) )
               {
                    parseDailyWipReport( fileList[i].getAbsolutePath() );

                    successFileList.add( fileList[i] );
               }
               if ( ( fileList[i].getName() != null ) && ( fileList[i].getName().trim().startsWith( UTACPOP3Adaptor.FILE_NAME_DAILY_SHIP ) || fileList[i].getName().trim().indexOf( UTACPOP3Adaptor.FILE_NAME_DAILY_SHIP ) != -1 ) )
               {
                    ArrayList utacShipList = parseDailyShipReport( fileList[i].getAbsolutePath() );

                   if ( utacShipList != null )
                   {
                       getShippingDetails( utacShipList );
                   }
                   successFileList.add( fileList[i] );
               }
              
               if ( fileList[i].getName() != null && fileList[i].getName().trim().startsWith( UTACPOP3Adaptor.FILE_NAME_DAILY_YIELD ) )
               {
                    ArrayList testBinList = parseFTYieldReport( fileList[i].getAbsolutePath() );

                   if ( testBinList != null && testBinList.size() > 0 )
                    {
                        //to get the UTAC Test Bin Details
                        if ( testBinList.isEmpty() == false )
                        {
                            log( "Updating UTAC Binning Information" );
                            TestAdaptorDAO.saveTestBinInfo ( null, testBinList , VENDOR_NAME_UTAC );
                            success = true;
                        }
                        else
                        {
                            log( "UTAC Binning Information List is Empty" );
                        }
                    }
                   successFileList.add( fileList[i] );
               }
           }
       }
       catch ( Exception e )
       {
           success = false;
           log( "ERROR!! ERROR!! ERROR!! While parsing and storing File " + e );
           e.printStackTrace();
           throw e;
       }

        // to save the Wafer Store lot tables
       try
       {
           if ( m_waferBankDataMap.isEmpty() == false )
           {
               log(" Updating Wafer Store Lot Information");
               InventoryLotDAO.saveInventoryLot( dbTransaction/*null*/, m_waferBankDataMap.values().iterator(), LOCATION_TYPE_WAFER_BANK, VENDOR_NAME_UTAC );
               success = true;
           }
           else
           {
               InventoryLotDAO.closeInventoryLot(dbTransaction/*null*/, LOCATION_TYPE_WAFER_BANK, VENDOR_NAME_UTAC  );
           }

      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Wafer Store Lot information into database: " + se);
          throw se;
      }

        // to save the SORT lot tables
       try
       {
           if ( m_sortDataMap.isEmpty() == false )
           {
               log( " Updating Sort Lot Information" );
               FabSortAdaptorDAO.saveSortLot( null, m_sortDataMap.values().iterator(), WIP_TYPE_SORT, VENDOR_NAME_UTAC );
               success = true;
           }
           else
           {
               FabSortAdaptorDAO.closeFabSortLot( dbTransaction, WIP_TYPE_SORT, VENDOR_NAME_UTAC );
           }
      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Sort Lot information into database: " + se);
          throw se;
      }
        try
        {
            // Save Sort Information
            if ( m_sortShipDataMap.isEmpty() == false )
            {
                log( " Updating Sort Shiping Lot Information" );
                ShippedLotDAO.saveShippedLot( null, m_sortShipDataMap.values().iterator() );
            }
            success = true;
            m_sortShipDataMap.clear();
            m_sortShipDataMap = null;
        }
        catch (ScalarException se)
        {
            success = false;
            se.printStackTrace();
            log( "ERROR!! ERROR!! ERROR!! Could not update Sort Shipping Lot information into database: " + se );
            throw se;
        }
       // to save the Die Bank lot tables
       try
       {
           if ( m_dieBankDataMap.isEmpty() == false )
           {
               log(" Updating Die Bank Lot Information");
               InventoryLotDAO.saveInventoryLot( dbTransaction/*null*/, m_dieBankDataMap.values().iterator(), INVENTORY_TYPE_DIE_BANK, VENDOR_NAME_UTAC );
               success = true;
           }
           else
           {
               InventoryLotDAO.closeInventoryLot(dbTransaction/*null*/, INVENTORY_TYPE_DIE_BANK, VENDOR_NAME_UTAC  );
           }
      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Assembly Lot information into database: " + se);
          throw se;
      }

       // to save the Assembly lot tables
       try
       {
           if ( m_assyWipDataMap.isEmpty() == false )
           {
               log(" Updating Assembly Lot Information");
               AssemblyAdaptorDAO.saveAssemblyLot( dbTransaction/*null*/, m_assyWipDataMap.values().iterator(), WIP_TYPE_ASSEMBLY, VENDOR_NAME_UTAC );
               success = true;
           }
           else
           {
               AssemblyAdaptorDAO.closeAssemblyLot(dbTransaction, WIP_TYPE_ASSEMBLY, VENDOR_NAME_UTAC );
           }
      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Assembly Lot information into database: " + se);
          throw se;
      }
        // to save the Class Stroe lot tables
       try
       {
           if ( m_preTestDataMap.isEmpty() == false )
           {
               log(" Updating Class Stroe Lot Information");
               InventoryLotDAO.saveInventoryLot( dbTransaction/*null*/, m_preTestDataMap.values().iterator(), LOCATION_TYPE_PRE_TEST, VENDOR_NAME_UTAC );
               success = true;
           }
           else
           {
               InventoryLotDAO.closeInventoryLot(dbTransaction/*null*/, LOCATION_TYPE_PRE_TEST, VENDOR_NAME_UTAC  );
           }
      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Class Stroe Lot information into database: " + se);
          throw se;
      }

      /*Updating the Test Lot Information*/
      try
      {
          // Save Test Information
          if( m_ftDataMap.isEmpty() == false )
          {
              log(" Updating Test Lot Information");
              TestAdaptorDAO.saveTestLot( dbTransaction/*null*/, m_ftDataMap.values().iterator(), LOCATION_TYPE_FT, VENDOR_NAME_UTAC );
              success = true;
          }
          else
          {
              TestAdaptorDAO.closeTestLot( dbTransaction, LOCATION_TYPE_FT, VENDOR_NAME_UTAC );
          }
      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Test Lot information into database: " + se);
          throw se;
      }

        // to save the EOL lot
         try
         {
             if ( m_eolDataMap.isEmpty() == false )
             {
                 log(" Updating EOL Lot Information");
                 InventoryLotDAO.saveInventoryLot( dbTransaction/*null*/, m_eolDataMap.values().iterator(), LOCATION_TYPE_EOL, VENDOR_NAME_UTAC );
                 success = true;
             }
             else
             {
                 InventoryLotDAO.closeInventoryLot(dbTransaction/*null*/, LOCATION_TYPE_EOL, VENDOR_NAME_UTAC  );
             }
        }
        catch (ScalarException se)
        {
            success = false;
            se.printStackTrace();
            log("ERROR!! ERROR!! ERROR!! Could not update EOL Lot information into database: " + se);
            throw se;
        }

        // to save the FG lot tables
       try
       {
           if ( m_fgDataMap.isEmpty() == false )
           {
               log(" Updating Finshed Goods Lot Information");
               InventoryLotDAO.saveInventoryLot( dbTransaction/*null*/, m_fgDataMap.values().iterator(), LOCATION_TYPE_FG, VENDOR_NAME_UTAC );
               success = true;
           }
           else
           {
               InventoryLotDAO.closeInventoryLot(dbTransaction/*null*/, LOCATION_TYPE_FG, VENDOR_NAME_UTAC  );
           }
      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Finshed Goods Lot information into database: " + se);
          throw se;
      }

       try
        {
            // Save FG Ship Information
            if ( m_fgShipDataMap.isEmpty() == false )
            {
                log( " Updating FG Shiping Lot Information" );
                ShippedLotDAO.saveShippedLot( null, m_fgShipDataMap.values().iterator() );
            }
            success = true;
            m_fgShipDataMap.clear();
            m_fgShipDataMap = null;
        }
        catch (ScalarException se)
        {
            success = false;
            se.printStackTrace();
            log( "ERROR!! ERROR!! ERROR!! Could not update FG Shipping Lot information into database: " + se );
            throw se;
        }

       // To Close the Drop Out Lots
      AdaptorDAO.closeDropOutLots( VENDOR_NAME_UTAC );
       
      // TO SEND THE NEW LOTS, NEW TRANSIT LOTS, NO PO LOTS, DISCREPANCY LOTS NOTIFICATIONS TO THE USER
      AdaptorDAO.sendAllNotifications( VENDOR_NAME_UTAC, true, true, true );



      int adaptor_id = AdaptorRunInfo.getLastRunAdaptorId( UTACPOP3Adaptor.ADAPTOR_NAME, CONSTANT_ADAPTOR);

      // Update Adaptor_Run_Info table
      try
      {
            if ( success == true )
            {
                AdaptorRunInfo.saveAdaptorLastUpdatedStatus(CONSTANT_PARSER, UTACPOP3Adaptor.ADAPTOR_NAME, CONSTANT_SUCCESS, adaptor_id);
                System.out.println( "SUCCESSFULLY UPDATED IN THE DATABASE" );
            }
      }
      catch ( ScalarException se )
      {
            success = false; //As filES DATA SAVED , UPDATEING AS SUCCESS
            AdaptorRunInfo.saveAdaptorLastUpdatedStatus(CONSTANT_PARSER, UTACPOP3Adaptor.ADAPTOR_NAME, CONSTANT_SUCCESS, adaptor_id);
            log( "WARNING!! WARNING!! WARNING!! Could not update Adaptor run information, Exception: " + se );
            throw se;
       }
        // Move the successful files to 'done' directory
       if ( success )
       {
           AdaptorUtils.moveFilesToDone( successFileList, doneDestDir );
       }
   }//end of execute method


    /**
     *
     * @param fileName
     * @return
     * @throws Exception
     */
    private void parseDailyWipReport(String fileName) throws Exception
    {
        if (fileName == null) throw new ScalarException("Filename argument is null");
                
        Sheet sheet;
        try
        {
            File lotstatusFile = new File(fileName);
            if (lotstatusFile.exists() == false)
            {
                throw new ScalarException(fileName + " doesnt exist");
            }

            log("\nFound " + fileName);
            log("Parsing the file for UTAC WIP Status Report...");
            System.out.println("\nFound " + fileName);
            System.out.println("Parsing the file for UTAC WIP Status Report...");

            Workbook workbook = Workbook.getWorkbook(lotstatusFile);

            for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++)
            {
                sheet = workbook.getSheet(sheetIndex);

                if (sheet.getName() != null && sheet.getName().indexOf("Wafer") != -1)
                {
                    log("sheet.getName() = " + sheet.getName());
                    ArrayList sortWipList = getWaferWipDetails(sheet);
                    if (sortWipList != null && sortWipList.size() > 0)
                    {
                       getAllSortWipLotDetails( sortWipList );
                    }
                }
                else
                {
                    log("sheet.getName() = " + sheet.getName());
                    ArrayList allWipList = getAllWipDetails(sheet);
                    if (allWipList != null && allWipList.size() > 0)
                    {
                        getAllWipLotDetails( allWipList );
                    }
                }

            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            throw ex;
        }
    }

     private ArrayList parseDailyShipReport( String fileName ) throws Exception
    {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );

        ArrayList shipList              = new ArrayList();
        String line                     = null;

        try
        {
            File detailShipFile = new File( fileName );
            if ( detailShipFile.exists() == false )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            log( "\nFound " + fileName );
            log( "\nParsing the file for CP/FG Ship Report..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for CP/FG Ship Report..." );

            BufferedReader reader = new BufferedReader( new FileReader( detailShipFile ) );
            reader.readLine();  // Read out <Report Name> Line
            reader.readLine();  // Read out <Report header> Line
            while ( ( line = reader.readLine() ) != null  && line.length() > 0 )
            {
                UTACShipStatus shipStatus = new UTACShipStatus();

                line = line.replaceAll( "\"", "" );

                String[] token = line.split( "," );

                for (int x = 0; x < token.length; x++)
                {
                    if (token[x] != null && token[x].trim().length() > 0)
                    {
                        switch (x)
                        {
                            case 0:
                                    shipStatus.setShipDate(token[x].trim() );
                                    break;
                            case 1:
									shipStatus.setInvoiceNo(token[x].trim() );
                                    break;
                            case 2:
                                    shipStatus.setNextLocation( token[x].trim() );
                                    break;
                            case 3:
                                    shipStatus.setPoNumber( token[x].trim() );
                                    break;
                            case 4:
                                    shipStatus.setDeviceName( token[x].trim());
                                    break;
                            case 5:
                                    shipStatus.setCustLotNo( token[x].trim());
                                    break;
                            case 6:
                                    if ( token[x].trim().indexOf(".") != -1 )
                                    {
                                        shipStatus.setVendorLotNo( token[x].trim() );
                                    }
                                    else
                                    {
                                        int len = token[x].trim().length();
                                        shipStatus.setVendorLotNo( token[x].trim().substring(0, (len-1 ) ) + "." +  token[x].trim().substring(len-1, len) );
                                    }
                                    break;
                            //case 7: Part ID not Required

                            case 8:
                                    if ( token[x].trim().indexOf(".") != -1 )
                                    {
                                        shipStatus.setShipQty( token[x].trim().substring(0, token[x].trim().indexOf(".")));
                                    }
                                    else
                                    {
                                        shipStatus.setShipQty( token[x].trim() );
                                    }
                                    break;
                            case 9:
                                    shipStatus.setDateCode ( "-".equalsIgnoreCase(token[x].trim()) ? null: token[x].trim() );
                                    break;
                            case 10:
                                    shipStatus.setSoNumber( token[x].trim() );
                                    break;
                            //case 11: //PGI DATE  not Required

                            case 12:
                                    shipStatus.setMawbNo( token[x].trim() );
                                    break;
                            case 13:
                                    shipStatus.setHawbNo( StringUtils.trimLeadingChar(token[x].trim(),'0' ));
                                    break;
                            case 14:
                                    shipStatus.setFlightNo( token[x].trim());
                                    break;
                            case 15:
                                    if ( token[x].trim().indexOf("/") != -1 )
                                    {
                                        shipStatus.setEtd( StringUtils.formatDate(token[x].trim().split(" ")[0], "MM/dd/yy", "MM/dd/yyyy") );
                                    }
                                    break;
                            case 16:
                                    if ( token[x].trim().indexOf("/") != -1 )
                                    {
                                        shipStatus.setEta( StringUtils.formatDate(token[x].trim().split(" ")[0], "MM/dd/yy", "MM/dd/yyyy") );
                                    }
                                    break;
                            //Remaing Fileds Not Required
                         }

                    }

                }
                if (shipStatus.getDeviceName() != null && shipStatus.getDeviceName().length() > 0 )
				{
                    shipList.add( shipStatus );
                }
            }

            try
            {
                if ( reader != null )
                {
                   reader.close();
                }
            }
            catch(IOException ignore)
            {

            }

        }
        catch ( Exception ex )
        {   System.out.println("ERROR!!!ERROR!!! While Parsing the UTAC Daily FG Shippment Sheet");
            ex.printStackTrace();
            throw ex;
        }

        return shipList;

    } // end of prase Daily FG ShipReport method

    private ArrayList getWaferWipDetails(Sheet cpWipSheet ) throws Exception
    {
        ArrayList waferWipList = new ArrayList();

        UTACPOP3WipStatus utacWipStatus = null;
        try
        {
            Cell[] row = null;

            for (int rowCount = 3; rowCount < cpWipSheet.getRows(); rowCount++)
            {
                row = cpWipSheet.getRow(rowCount);

                utacWipStatus = new UTACPOP3WipStatus();

                if (row.length > 0)
                {
                    if (row[0].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setCustomerDevice(null);
                    }
                    else
                    {
                        utacWipStatus.setCustomerDevice(row[0].getContents().trim());
                    }
                }
                if (row.length > 1)
                {
                    if (row[1].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setCustPartIn(null);
                    }
                    else
                    {
                        utacWipStatus.setCustPartIn(row[1].getContents().trim());
                    }
                }
                if (row.length > 2)
                {
                    if (row[2].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setCustomerLotId(null);
                    }
                    else
                    {
                        utacWipStatus.setCustomerLotId(row[2].getContents().trim());
                    }
                }
                //Row 3 Not required

                if (row.length > 4)
                {
                    if (row[4].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setReceiveDate(null);
                    }
                    else if( row[4].getType().equals( CellType.DATE ) )
                    {
                        DateCell dc = (DateCell) row[4];
                        java.util.Date dateIn = null;
                        dateIn = dc.getDate();

                        if ("America/Los_Angeles".equals(System.getProperty("user.timezone")))
                        {
                            Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ), Locale.US );
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            utacWipStatus.setReceiveDate( StringUtils.formatDateToString( dateIn,"MM/dd/yyyy HH:mm:ss" )  ) ;
                        }
                        else
                        {
                            Calendar cal = new GregorianCalendar();
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            utacWipStatus.setReceiveDate(StringUtils.formatDateToString(dateIn, "MM/dd/yyyy HH:mm:ss"));
                        }
                    }
                    else
                    {
                        utacWipStatus.setReceiveDate(row[4].getContents().trim());
                    }
                }
                if (row.length > 5)
                {
                    if (row[5].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setLotStartDate(null);
                    }
                    else if( row[5].getType().equals( CellType.DATE ) )
                    {
                        DateCell dc = (DateCell) row[5];
                        java.util.Date dateIn = null;
                        dateIn = dc.getDate();

                        if ("America/Los_Angeles".equals(System.getProperty("user.timezone")))
                        {
                            Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ), Locale.US );
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            utacWipStatus.setLotStartDate( StringUtils.formatDateToString( dateIn,"MM/dd/yyyy HH:mm:ss" )  ) ;
                        }
                        else
                        {
                            Calendar cal = new GregorianCalendar();
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            utacWipStatus.setLotStartDate(StringUtils.formatDateToString(dateIn, "MM/dd/yyyy HH:mm:ss"));
                        }
                    }
                    else
                    {
                        utacWipStatus.setLotStartDate(row[5].getContents().trim());
                    }
                }
                if (row.length > 6)
                {
                    if (row[6].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setUtacLotId(null);
                    }
                    else
                    {
                        utacWipStatus.setUtacLotId(row[6].getContents().trim());
                    }
                }
                if (row.length > 7)
                {
                    if (row[7].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setProArea(null);
                    }
                    else
                    {
                        utacWipStatus.setProArea(row[7].getContents().trim());
                    }
                }
                if (row.length > 8)
                {
                    if (row[8].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setStage(null);
                    }
                    else
                    {
                        utacWipStatus.setStage(row[8].getContents().trim());
                    }
                }
                if (row.length > 9)
                {
                    if (row[9].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setState(null);
                    }
                    else
                    {
                        utacWipStatus.setState( row[9].getContents().trim() );
                    }
                }
                if (row.length > 10)
                {
                    if (row[10].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setWaferQty(null);
                    }
                    else
                    {
                        utacWipStatus.setWaferQty( row[10].getContents().trim());
                    }
                }
                if (row.length > 11)
                {
                    if (row[11].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setDieQtyIn(null);
                    }
                    else
                    {
                        utacWipStatus.setDieQtyIn(row[11].getContents().trim());
                    }
                }
                if (row.length > 12)
                {
                    if (row[12].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setExpectedDateOut(null);
                    }
                    else if( row[12].getType().equals( CellType.DATE ) )
                    {
                        DateCell dc = (DateCell) row[12];
                        java.util.Date dateIn = null;
                        dateIn = dc.getDate();

                        if ("America/Los_Angeles".equals(System.getProperty("user.timezone")))
                        {
                            Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ), Locale.US );
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            utacWipStatus.setExpectedDateOut( StringUtils.formatDateToString( dateIn,"MM/dd/yyyy HH:mm:ss" )  ) ;
                        }
                        else
                        {
                            Calendar cal = new GregorianCalendar();
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            utacWipStatus.setExpectedDateOut(StringUtils.formatDateToString(dateIn, "MM/dd/yyyy HH:mm:ss"));
                        }
                    }
                    else
                    {
                        utacWipStatus.setExpectedDateOut(row[12].getContents().trim());
                    }
                }
                //Row 13 Not Required

                if (row.length > 14)
                {
                    if (row[14].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setLotComments(null);
                    }
                    else
                    {
                        utacWipStatus.setLotComments(row[14].getContents().trim());
                    }
                }

                if ( utacWipStatus.getCustomerDevice() != null && utacWipStatus.getCustomerDevice().length() > 0 )
                {
                    waferWipList.add( utacWipStatus );
                }

           }

        }
        catch(Exception e)
        {
            System.out.println("ERROR!! ERROR!! While parsing the UTAC Sort Wip sheet........" + e );
            log("ERROR!! ERROR!! While parsing the UTAC Sort Wip sheet........" + e );
            e.printStackTrace();
        }
        return waferWipList;
    }

    private ArrayList getAllWipDetails(Sheet allWipSheet ) throws Exception
    {
        ArrayList allWipList = new ArrayList();

        UTACPOP3WipStatus utacWipStatus = null;
        try
        {
            Cell[] row = null;

            for (int rowCount = 3; rowCount < allWipSheet.getRows(); rowCount++)
            {
                row = allWipSheet.getRow(rowCount);

                utacWipStatus = new UTACPOP3WipStatus();

                if (row.length > 0)
                {
                    if (row[0].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setCustomerDevice(null);
                    }
                    else
                    {
                        utacWipStatus.setCustomerDevice(row[0].getContents().trim());
                    }
                }
                if (row.length > 1)
                {
                    if (row[1].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setCustPartIn(null);
                    }
                    else
                    {
                        utacWipStatus.setCustPartIn(row[1].getContents().trim());
                    }
                }
                if (row.length > 2)
                {
                    if (row[2].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setCustomerLotId(null);
                    }
                    else
                    {
                        utacWipStatus.setCustomerLotId(row[2].getContents().trim());
                    }
                }
                if (row.length > 3)
                {
                    if (row[3].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setDateCode(null);
                    }
                    else
                    {
                        utacWipStatus.setDateCode(row[3].getContents().trim());
                    }
                }
                //ROW 4 RECEIVED QTY Not Required

                if (row.length > 5)
                {
                    if (row[5].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setReceiveDate(null);
                    }
                    else if( row[5].getType().equals( CellType.DATE ) )
                    {
                        DateCell dc = (DateCell) row[5];
                        java.util.Date dateIn = null;
                        dateIn = dc.getDate();

                        if ("America/Los_Angeles".equals(System.getProperty("user.timezone")))
                        {
                            Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ), Locale.US );
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            utacWipStatus.setReceiveDate( StringUtils.formatDateToString( dateIn, "MM/dd/yyyy HH:mm:ss")  ) ;
                        }
                        else
                        {
                            Calendar cal = new GregorianCalendar();
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            utacWipStatus.setReceiveDate(StringUtils.formatDateToString(dateIn,"MM/dd/yyyy HH:mm:ss"));
                        }
                    }
                    else
                    {
                        utacWipStatus.setReceiveDate(row[5].getContents().trim());
                    }
                }
                if (row.length >6)
                {
                    if (row[6].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setLotStartDate(null);
                    }
                    else if( row[6].getType().equals( CellType.DATE ) )
                    {
                        DateCell dc = (DateCell) row[6];
                        java.util.Date dateIn = null;
                        dateIn = dc.getDate();
                        if ( "U9135288.1".equalsIgnoreCase(row[7].getContents().trim()))
                            {
                            System.out.println("d.getDATE = " + dateIn);
                            }
                        if ("America/Los_Angeles".equals(System.getProperty("user.timezone")))
                        {
                            Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ), Locale.US );
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();

                            utacWipStatus.setLotStartDate( StringUtils.formatDateToString( dateIn,"MM/dd/yyyy HH:mm:ss" )  ) ;
                        }
                        else
                        {
                            Calendar cal = new GregorianCalendar();
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            if ( "U9135288.1".equalsIgnoreCase(row[7].getContents().trim()))
                            {
                                System.out.println("dateIn = " + dateIn);
                            }
                            utacWipStatus.setLotStartDate(StringUtils.formatDateToString(dateIn,"MM/dd/yyyy HH:mm:ss"));
                            if ( "U9135288.1".equalsIgnoreCase(row[7].getContents().trim()))
                            {
                                System.out.println("utacWipStatus.getLotStartDate() = " + utacWipStatus.getLotStartDate());
                            }
                        }
                    }
                    else
                    {
                        utacWipStatus.setLotStartDate(row[6].getContents().trim());
                    }
                }
                if (row.length >7)
                {
                    if (row[7].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setUtacLotId(null);
                    }
                    else
                    {
                        utacWipStatus.setUtacLotId(row[7].getContents().trim());
                    }
                }
                if (row.length > 8)
                {
                    if (row[8].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setProArea(null);
                    }
                    else
                    {
                        utacWipStatus.setProArea(row[8].getContents().trim());
                    }
                }
                if (row.length > 9)
                {
                    if (row[9].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setStage(null);
                    }
                    else
                    {
                        utacWipStatus.setStage(row[9].getContents().trim());
                    }
                }
                if (row.length > 10)
                {
                    if (row[10].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setState(null);
                    }
                    else
                    {
                        utacWipStatus.setState( row[10].getContents().trim() );
                    }
                }
                
                if (row.length > 11)
                {
                    if (row[11].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setDieQtyIn(null);
                    }
                    else
                    {
                        utacWipStatus.setDieQtyIn(row[11].getContents().trim());
                    }
                }
                if (row.length > 12)
                {
                    if (row[12].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setExpectedDateOut(null);
                    }
                    else if( row[12].getType().equals( CellType.DATE ) )
                    {
                        DateCell dc = (DateCell) row[12];
                        java.util.Date dateIn = null;
                        dateIn = dc.getDate();

                        if ("America/Los_Angeles".equals(System.getProperty("user.timezone")))
                        {
                            Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ), Locale.US );
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            utacWipStatus.setExpectedDateOut( StringUtils.formatDateToString( dateIn,"MM/dd/yyyy HH:mm:ss")  ) ;
                        }
                        else
                        {
                            Calendar cal = new GregorianCalendar();
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            utacWipStatus.setExpectedDateOut(StringUtils.formatDateToString(dateIn,"MM/dd/yyyy HH:mm:ss"));
                        }
                    }
                    else
                    {
                        utacWipStatus.setExpectedDateOut(row[12].getContents().trim());
                    }
                }
                //Row 13 Not Required

                if (row.length > 14)
                {
                    if (row[14].getType().equals(CellType.EMPTY))
                    {
                        utacWipStatus.setLotComments(null);
                    }
                    else
                    {
                        utacWipStatus.setLotComments(row[14].getContents().trim());
                    }
                }

                if ( utacWipStatus.getCustomerDevice() != null && utacWipStatus.getCustomerDevice().length() > 0 )
                {
                    allWipList.add( utacWipStatus );
                }

           }

        }
        catch(Exception e)
        {
            System.out.println("ERROR!! ERROR!! While parsing the UTAC Assy & Test Wip sheet........" + e );
            log("ERROR!! ERROR!! While parsing the UTAC Assy & Test Wip sheet........" + e );
            e.printStackTrace();
        }
        return allWipList;
    }

    private ArrayList parseFTYieldReport( String fileName ) throws Exception
    {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );

        ArrayList ftYieldList  = new ArrayList();
        TestLotBinReport ftYieldStatus  = null;
        
        try
        {
            File detailWipFile = new File( fileName );
            if ( detailWipFile.exists() == false )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            log( "\nFound " + fileName );
            log( "\nParsing the file for UTAC FT Yield Info..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for UTAC FT Yield Info..." );

            Workbook workbook = Workbook.getWorkbook( detailWipFile );
            Sheet sheet = workbook.getSheet( 0 );
            Cell[] row = null;

            for ( int rowCount = 5; rowCount < sheet.getRows(); rowCount++ )
            {
                row = sheet.getRow( rowCount );

                ftYieldStatus = new TestLotBinReport();
                //ROW 0, 1 not Required
                if( row.length > 2 )
                {
                    if ( row[2].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setDeviceName( null );
                    }
                    else
                    {
                        ftYieldStatus.setDeviceName( row[2].getContents().trim() );
                    }
                }
                if( row.length > 3 )
                {
                    if ( row[3].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setPkgType( null );
                    }
                    else
                    {
                        ftYieldStatus.setPkgType( row[3].getContents().trim() );
                    }
                }
                if( row.length > 4)
                {
                    if ( row[4].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setLeadCount( null );
                    }
                    else
                    {
                        ftYieldStatus.setLeadCount(row[4].getContents().trim());
                    }
                }
                if( row.length > 5)
                {
                    if ( row[5].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setCustLotNo( null );
                    }
                    else
                    {
                        ftYieldStatus.setCustLotNo( row[5].getContents().trim());
                    }
                }

                if ( row.length > 6 )
                {
                   if ( row[6].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setLotNumber( null );
                    }
                    else
                    {
                        ftYieldStatus.setLotNumber( row[6].getContents().trim());
                    }
                }
                 //Row 7, 8, 9 10
                if( row.length > 11 )
                {
                    if ( row[11].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setTesterId( null );
                    }
                    else
                    {
                        ftYieldStatus.setTesterId( row[11].getContents().trim());
                    }
                }
                //12
                if( row.length > 13 )
                {
                    if ( row[13].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setHandler( null );
                    }
                    else
                    {
                        ftYieldStatus.setHandler( row[13].getContents().trim());
                    }
                }
                // 14
                if( row.length >15 )
                {
                    if ( row[15].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setLb( null );
                    }
                    else
                    {
                        ftYieldStatus.setLb( row[15].getContents().trim());
                    }
                }
                if( row.length >16 )
                {
                    if ( row[16].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setTestProg( null );
                    }
                    else
                    {
                        ftYieldStatus.setTestProg( row[16].getContents().trim());
                    }
                }
                //17
                if( row.length >18 )
                {
                    if ( row[18].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setDateIn( null );
                    }
                    else if( row[18].getType().equals( CellType.DATE ) )
                    {
                        DateCell dc = (DateCell) row[18];
                        java.util.Date dateIn = null;
                        dateIn = dc.getDate();

                        if ("America/Los_Angeles".equals(System.getProperty("user.timezone")))
                        {
                            Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ), Locale.US );
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            ftYieldStatus.setDateIn( StringUtils.formatDateToString( dateIn, "MM/dd/yyyy HH:mm:ss" )  ) ;
                        }
                        else
                        {
                            Calendar cal = new GregorianCalendar();
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            ftYieldStatus.setDateIn(StringUtils.formatDateToString(dateIn, "MM/dd/yyyy HH:mm:ss"));
                        }
                    }
                    else
                    {
                        ftYieldStatus.setDateIn( row[18].getContents().trim());
                    }
                }
                if( row.length >19 )
                {
                    if ( row[19].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setDateOut( null );
                    }
                    else if( row[19].getType().equals( CellType.DATE ) )
                    {
                        DateCell dc = (DateCell) row[19];
                        java.util.Date dateIn = null;
                        dateIn = dc.getDate();

                        if ("America/Los_Angeles".equals(System.getProperty("user.timezone")))
                        {
                            Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ), Locale.US );
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            ftYieldStatus.setDateOut( StringUtils.formatDateToString( dateIn ,"MM/dd/yyyy HH:mm:ss")  ) ;
                        }
                        else
                        {
                            Calendar cal = new GregorianCalendar();
                            cal.setTime(dateIn);
                            dateIn = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE), cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),cal.get(Calendar.SECOND)).getTime();
                            ftYieldStatus.setDateOut(StringUtils.formatDateToString(dateIn, "MM/dd/yyyy HH:mm:ss"));
                        }
                    }
                    else
                    {
                        ftYieldStatus.setDateOut( row[19].getContents().trim());
                    }
                }
                if( row.length > 20 )
                {
                    if ( row[20].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setInQty( null );
                    }
                    else
                    {
                        ftYieldStatus.setInQty( row[20].getContents().trim());
                    }
                }
                if( row.length > 21 )
                {
                    if ( row[21].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setPassQty( null );
                    }
                    else
                    {
                        ftYieldStatus.setPassQty( row[21].getContents().trim());
                    }
                }
                if( row.length > 22 )
                {
                    if ( row[22].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setYield( null );
                    }
                    else
                    {
                        ftYieldStatus.setYield( row[22].getContents().trim().replaceAll("%", ""));
                    }
                }
                //23
                if( row.length > 24 )
                {
                    if ( row[24].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setOsQty( null );
                    }
                    else
                    {
                        ftYieldStatus.setOsQty( row[24].getContents().trim());
                    }
                }
                if( row.length > 25 )
                {
                    if ( row[25].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setOSRate( null );
                    }
                    else
                    {
                        ftYieldStatus.setOSRate( row[25].getContents().trim().replaceAll("%", ""));
                    }
                }
                //26
                if( row.length > 27 )
                {
                    if ( row[27].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setBin1( null );
                    }
                    else
                    {
                        ftYieldStatus.setBin1( row[27].getContents().trim());
                    }
                }
                if( row.length > 28 )
                {
                    if ( row[28].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setBin2( null );
                    }
                    else
                    {
                        ftYieldStatus.setBin2( row[28].getContents().trim());
                    }
                }
                if( row.length > 29 )
                {
                    if ( row[29].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setBin3( null );
                    }
                    else
                    {
                        ftYieldStatus.setBin3( row[29].getContents().trim());
                    }
                }
                if( row.length > 30 )
                {
                    if ( row[30].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setBin4( null );
                    }
                    else
                    {
                        ftYieldStatus.setBin4( row[30].getContents().trim());
                    }
                }
                if( row.length > 31 )
                {
                    if ( row[31].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setBin5( null );
                    }
                    else
                    {
                        ftYieldStatus.setBin5( row[31].getContents().trim());
                    }
                }
                if( row.length > 32)
                {
                    if ( row[32].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setBin6( null );
                    }
                    else
                    {
                        ftYieldStatus.setBin6( row[32].getContents().trim());
                    }
                }
                if( row.length > 33 )
                {
                    if ( row[33].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setBin7( null );
                    }
                    else
                    {
                        ftYieldStatus.setBin7( row[33].getContents().trim());
                    }
                }
                if( row.length > 34 )
                {
                    if ( row[34].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setBin8( null );
                    }
                    else
                    {
                        ftYieldStatus.setBin8( row[34].getContents().trim());
                    }
                }
                if( row.length > 35 )
                {
                    if ( row[35].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setBin9( null );
                    }
                    else
                    {
                        ftYieldStatus.setBin9( row[35].getContents().trim());
                    }
                }
                if( row.length > 36 )
                {
                    if ( row[36].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setBin10( null );
                    }
                    else
                    {
                        ftYieldStatus.setBin10( row[36].getContents().trim());
                    }
                }
                if( row.length > 37 )
                {
                    if ( row[37].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setVmQty( null );
                    }
                    else
                    {
                        ftYieldStatus.setVmQty( row[37].getContents().trim());
                    }
                }
                if( row.length > 38 )
                {
                    if ( row[38].getType().equals(CellType.EMPTY) )
                    {
                        ftYieldStatus.setLossQty( null );
                    }
                    else
                    {
                        ftYieldStatus.setLossQty( row[38].getContents().trim());
                    }
                }

                ftYieldList.add( ftYieldStatus );
            }
        }
        catch ( Exception ex )
        {   System.out.println("ERROR!!!ERROR!!! While Parsing the UTAC FT Month Yield Report");
            ex.printStackTrace();
            throw ex;
        }

        return ftYieldList;
    }
    private void getAllSortWipLotDetails(ArrayList allWipList) throws Exception
    {
        UTACPOP3WipStatus wipStatus = null;
        InventoryLot inventoryLot   = null;
        FabSortLot sortLot          = null;
        String partNumber           = null;
        String lotNumber            = null;
        String fabLotNumber         = null;
        String lotStatus            = null;

        if ( allWipList == null || allWipList.size() <= 0 )
        {
            return;
        }

        try
        {
            Iterator iterator = allWipList.iterator();

            while (iterator.hasNext())
            {
                wipStatus = (UTACPOP3WipStatus) iterator.next();

                fabLotNumber = wipStatus.getCustomerLotId();
                partNumber = wipStatus.getCustomerDevice();
                lotNumber  = wipStatus.getUtacLotId();

                if( wipStatus.getState() != null && ( "WAIT".equalsIgnoreCase( wipStatus.getState())
                        || "HELD".equalsIgnoreCase( wipStatus.getState()) || wipStatus.getState().indexOf("HLD") != -1 ) )
                {
                    lotStatus = LOT_STATUS_HOLD;
                }
                else
                {
                    lotStatus = LOT_STATUS_RUNNING;
                }

                if ( lotNumber != null && lotNumber.trim().length() > 0 && partNumber != null && partNumber.trim().length() > 0)
                {
                    //DIE BANK LOTS
                    if ( wipStatus.getProArea() != null && "WAFER".equalsIgnoreCase( wipStatus.getProArea() ) )
                    {
                        log("In Wafer Store " + lotNumber );
                        inventoryLot = (InventoryLot) m_waferBankDataMap.get( partNumber + fabLotNumber );
                        if ( inventoryLot == null )
                        {
                            inventoryLot = new InventoryLot(VENDOR_NAME_UTAC, LOCATION_TYPE_WAFER_STORE );
                            m_waferBankDataMap.put( partNumber + fabLotNumber, inventoryLot );
                        }
                        int quantity = 0;
                        if (inventoryLot.getWaferQtyIn() != null)
                        {
                            try
                            {
                                quantity = Integer.parseInt(inventoryLot.getWaferQtyIn());
                            }
                            catch (NumberFormatException ignore) {
                            }
                            try
                            {
                                quantity += Integer.parseInt(wipStatus.getWaferQty() );
                            }
                            catch (NumberFormatException nfe) {
                            }
                        }
                        else
                        {
                            try
                            {
                                quantity = Integer.parseInt( wipStatus.getWaferQty() );
                            }
                            catch (NumberFormatException ignore) {
                            }
                        }

                        if ( quantity > 0 )
                        {
                            inventoryLot.setLotNumber( fabLotNumber );
                            inventoryLot.setVendorLot( lotNumber );
                            inventoryLot.setPartNumber( partNumber );
                            inventoryLot.setStatus( lotStatus );
                            inventoryLot.setFabLotNumber( fabLotNumber );
                            inventoryLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                            inventoryLot.setWaferQtyIn( quantity +"" );
                            inventoryLot.setStage( wipStatus.getStage());
                            inventoryLot.setDateIn( wipStatus.getLotStartDate() );
                        }
                    }

                    //SORT
                    if( wipStatus.getProArea() != null && "TEST".equalsIgnoreCase( wipStatus.getProArea() )  )
                    {
                        log( "In Sort " + lotNumber ) ;

                        sortLot = (FabSortLot) m_sortDataMap.get( partNumber + fabLotNumber );
                        if (sortLot == null)
                        {
                            sortLot = new FabSortLot( VENDOR_NAME_UTAC, WIP_TYPE_SORT );
                            m_sortDataMap.put( partNumber + fabLotNumber, sortLot);
                        }

                        int quantity = 0;
                        if (sortLot.getQtyIn() != null)
                        {
                            try
                            {
                                quantity = Integer.parseInt(sortLot.getQtyIn());
                            }
                            catch (NumberFormatException ignore) {
                            }
                            try
                            {
                                quantity += Integer.parseInt(wipStatus.getWaferQty());
                            }
                            catch (NumberFormatException nfe) {
                            }
                        }
                        else
                        {
                            try
                            {
                                quantity = Integer.parseInt(wipStatus.getWaferQty() );
                            }
                            catch (NumberFormatException ignore) {
                            }
                        }
                        if ( quantity > 0 )
                        {
                            sortLot.setLotId( fabLotNumber );
                            sortLot.setCustProduct( partNumber );
                            sortLot.setStage( wipStatus.getStage() );
                            sortLot.setFabLotNumber( fabLotNumber );

                            sortLot.setLotCategory ( LOT_CATEGORY_TYPE_PROD );
                            if ( wipStatus.getLotStartDate()  != null && wipStatus.getLotStartDate().length() > 8 )
                            {
                                sortLot.setDateIn( wipStatus.getLotStartDate() ) ;
                            }
                            else
                            {
                                sortLot.setDateIn( wipStatus.getReceiveDate() ) ;
                            }
                            if ( wipStatus.getExpectedDateOut() != null && wipStatus.getExpectedDateOut().length() > 8 )
                            {
                                sortLot.setForcastedDateOut( StringUtils.formatDate(wipStatus.getExpectedDateOut(), "dd-MMM-yyy hh:mm:ss", "MM/dd/yyyy HH:mm:ss" ) );
                            }
                            sortLot.setLotStatus( lotStatus );
                        }
                    }
                }
            }
        }
        catch( Exception e)
        {
            System.out.println("ERROR!! ERROR!! While parsing the UTAC Wafer Store & Sort Wip Data Details........" + e );
            e.printStackTrace();
            throw e;
        }
    }

    private void getAllWipLotDetails(ArrayList allWipList) throws Exception
    {
        UTACPOP3WipStatus wipStatus = null;
        InventoryLot inventoryLot   = null;
        AssemblyLot assemblyLot     = null;
        TestLot testLot             = null;
        String partNumber           = null;
        String lotNumber            = null;
        String fabLotNumber         = null;
        String lotStatus            = null;

        if ( allWipList == null || allWipList.size() <= 0 )
        {
            return;
        }

        try
        {
            Iterator iterator = allWipList.iterator();

            while (iterator.hasNext())
            {
                wipStatus = (UTACPOP3WipStatus) iterator.next();

                fabLotNumber = wipStatus.getCustomerLotId();
                partNumber = wipStatus.getCustomerDevice();
                lotNumber  = wipStatus.getUtacLotId();
                
                if( wipStatus.getState() != null && ( "WAIT".equalsIgnoreCase( wipStatus.getState())
                        || "HELD".equalsIgnoreCase( wipStatus.getState()) || wipStatus.getState().indexOf("HLD") != -1 ) )
                {
                    lotStatus = LOT_STATUS_HOLD;
                }
                else
                {
                    lotStatus = LOT_STATUS_RUNNING;
                }

                if ( lotNumber != null && lotNumber.trim().length() > 0 && partNumber != null && partNumber.trim().length() > 0)
                {
                    //DIE BANK LOTS
                    if ( wipStatus.getProArea() != null && "ASSEMBLY".equalsIgnoreCase( wipStatus.getProArea() ) && "P200-DBANK".equalsIgnoreCase( wipStatus.getStage() ) )
                    {
                        /*int bomPocessstep_id = NewAdaptorDAO.getBOMProcessStepId( partNumber , WIP_TYPE_ASSEMBLY );

                        if ( bomPocessstep_id > 0 )
                        {
                            log ( "In BOM Die bank--> Assembly Bom " + lotNumber );
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get( partNumber + lotNumber + fabLotNumber );
                            if (assemblyLot == null)
                            {
                                assemblyLot = new AssemblyLot( VENDOR_NAME_UTAC,  WIP_TYPE_ASSEMBLY );
                                m_assyWipDataMap.put( partNumber + lotNumber + fabLotNumber, assemblyLot);
                            }
                            int quantity = 0;
                            if (assemblyLot.getQtyIn() != null)
                            {
                                try
                                {
                                    quantity = Integer.parseInt(assemblyLot.getQtyIn());
                                }
                                catch (NumberFormatException ignore) {
                                }
                                try
                                {
                                    quantity += Integer.parseInt(wipStatus.getDieQtyIn());
                                }
                                catch (NumberFormatException nfe) {
                                }
                            }
                            else
                            {
                                try
                                {
                                    quantity = Integer.parseInt( wipStatus.getDieQtyIn() );
                                }
                                catch (NumberFormatException ignore) {
                                }
                            }

                            if ( quantity > 0 )
                            {
                                assemblyLot.setDeviceName(partNumber);
                                assemblyLot.setLotNumber(lotNumber);
                                assemblyLot.setQtyIn(quantity + "");
                                assemblyLot.setDateIn(wipStatus.getLotStartDate());
                                assemblyLot.setFabLotNumber(fabLotNumber);
                                assemblyLot.setStatus(lotStatus );
                                assemblyLot.setHoldReason( wipStatus.getHoldReason() );
                                assemblyLot.setCategory(LOT_CATEGORY_TYPE_PROD);
                                assemblyLot.setStage( wipStatus.getStage() );
                                assemblyLot.setDateCode( wipStatus.getDateCode() );

                                if ( wipStatus.getExpectedDateOut() != null && wipStatus.getExpectedDateOut().length() > 8 )
                                {
                                     assemblyLot.setExpectedDateOut(StringUtils.formatDate(wipStatus.getExpectedDateOut(), "dd-MMM-yyy hh:mm:ss", "MM/dd/yyyy" ));
                                }
                            }
                        }
                        else
                        {*/
                            log("In Die Bank " + lotNumber );

                            if ( partNumber.endsWith("-00") )
                            {
                                partNumber = partNumber.substring(0, partNumber.lastIndexOf("-00") );
                            }

                            inventoryLot = (InventoryLot) m_dieBankDataMap.get( partNumber + fabLotNumber  );
                            if ( inventoryLot == null )
                            {
                                inventoryLot = new InventoryLot(VENDOR_NAME_UTAC, LOCATION_TYPE_DIE_BANK );
                                m_dieBankDataMap.put( partNumber + fabLotNumber , inventoryLot );
                            }
                            int quantity = 0;
                            if (inventoryLot.getQtyIn() != null)
                            {
                                try
                                {
                                    quantity = Integer.parseInt(inventoryLot.getQtyIn());
                                }
                                catch (NumberFormatException ignore) {
                                }
                                try
                                {
                                    quantity += Integer.parseInt(wipStatus.getDieQtyIn() );
                                }
                                catch (NumberFormatException nfe) {
                                }
                            }
                            else
                            {
                                try
                                {
                                    quantity = Integer.parseInt( wipStatus.getDieQtyIn() );
                                }
                                catch (NumberFormatException ignore) {
                                }
                            }

                            if ( quantity > 0 )
                            {
                                inventoryLot.setLotNumber( fabLotNumber );
                                inventoryLot.setPartNumber( partNumber );
                                inventoryLot.setStatus( lotStatus );
                                inventoryLot.setFabLotNumber( fabLotNumber );
                                inventoryLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                                inventoryLot.setQtyIn( quantity +"" );
                                inventoryLot.setDateIn( wipStatus.getLotStartDate() );
                            }
                        //}
                    }
                    //ASSEMBLY
                    if( wipStatus.getProArea() != null && ("ASSEMBLY".equalsIgnoreCase( wipStatus.getProArea() ) || "FINISH".equalsIgnoreCase( wipStatus.getProArea() ) ) &&  !"P200-DBANK".equalsIgnoreCase( wipStatus.getStage() ) )
                    {
                        log( "In Assembly " + lotNumber ) ;

                        assemblyLot = (AssemblyLot) m_assyWipDataMap.get( partNumber + lotNumber + fabLotNumber );
                        if (assemblyLot == null)
                        {
                            assemblyLot = new AssemblyLot( VENDOR_NAME_UTAC );
                            m_assyWipDataMap.put( partNumber + lotNumber + fabLotNumber, assemblyLot);
                        }

                        int quantity = 0;
                        if (assemblyLot.getQtyIn() != null)
                        {
                            try
                            {
                                quantity = Integer.parseInt(assemblyLot.getQtyIn());
                            }
                            catch (NumberFormatException ignore) {
                            }
                            try
                            {
                                quantity += Integer.parseInt(wipStatus.getDieQtyIn());
                            }
                            catch (NumberFormatException nfe) {
                            }
                        }
                        else
                        {
                            try
                            {
                                quantity = Integer.parseInt(wipStatus.getDieQtyIn());
                            }
                            catch (NumberFormatException ignore) {
                            }
                        }
                        if ( quantity > 0 )
                        {
                            assemblyLot.setDeviceName(partNumber);
                            assemblyLot.setLotNumber(lotNumber);
                            assemblyLot.setQtyIn(quantity + "");
                            assemblyLot.setDateIn(wipStatus.getLotStartDate());
                            assemblyLot.setFabLotNumber(fabLotNumber);
                            assemblyLot.setStatus(lotStatus );
                            assemblyLot.setHoldReason( wipStatus.getHoldReason() );
                            assemblyLot.setCategory(LOT_CATEGORY_TYPE_PROD);
                            assemblyLot.setStage( wipStatus.getStage() );
                            assemblyLot.setDateCode( wipStatus.getDateCode() );

                            if ( wipStatus.getExpectedDateOut() != null && wipStatus.getExpectedDateOut().length() > 8 )
                            {
                                 assemblyLot.setExpectedDateOut(StringUtils.formatDate(wipStatus.getExpectedDateOut(), "dd-MMM-yyy hh:mm:ss", "MM/dd/yyyy" ));
                            }
                        }
                    }

                    //CLASS STORE & TEST
                    if( wipStatus.getProArea() != null && "TEST".equalsIgnoreCase(wipStatus.getProArea() ) )
                    {
                        if ( !"P400-PCC".equalsIgnoreCase(wipStatus.getStage() ) &&  !"P400-PCC2".equalsIgnoreCase(wipStatus.getStage() ))
                        {
                            log( "In Test " + lotNumber );

                            testLot = (TestLot) m_ftDataMap.get( partNumber + lotNumber + fabLotNumber);

                            if (testLot == null)
                            {
                                testLot = new TestLot(VENDOR_NAME_UTAC );
                                m_ftDataMap.put( partNumber + lotNumber + fabLotNumber, testLot);
                            }

                            int quantity = 0;
                            if (testLot.getQtyIn() != null)
                            {
                                try
                                {
                                    quantity = Integer.parseInt(testLot.getQtyIn());
                                }
                                catch (NumberFormatException ignore) {
                                }
                                try
                                {
                                    quantity += Integer.parseInt(wipStatus.getDieQtyIn());
                                }
                                catch (NumberFormatException nfe) {
                                }
                            }
                            else
                            {
                                try
                                {
                                    quantity = Integer.parseInt(wipStatus.getDieQtyIn());
                                }
                                catch (NumberFormatException ignore) {
                                }
                            }
                            if ( quantity > 0 )
                            {
                                testLot.setPartNumber(partNumber);
                                testLot.setLotNumber(lotNumber);
                                testLot.setQtyIn(quantity + "");
                                testLot.setDateIn(wipStatus.getLotStartDate());

                                if ( wipStatus.getExpectedDateOut() != null && wipStatus.getExpectedDateOut().length() > 8 )
                                {
                                     testLot.setExpecetedDate(StringUtils.formatDate(wipStatus.getExpectedDateOut(), "dd-MMM-yyy hh:mm:ss", "MM/dd/yyyy" ));
                                }
                                testLot.setFabLotNumber(fabLotNumber);
                                testLot.setStatus(lotStatus);
                                testLot.setHoldReason( wipStatus.getHoldReason() );
                                testLot.setPsType(LOCATION_TYPE_FT);
                                testLot.setCategory(LOT_CATEGORY_TYPE_PROD );
                                testLot.setStage( wipStatus.getStage() );
                                testLot.setDateCode( wipStatus.getDateCode() );
                            }
                        }
                        else
                        {
                            log( "In Pre Test " + lotNumber );

                            inventoryLot = (InventoryLot) m_preTestDataMap.get( partNumber + lotNumber + fabLotNumber);

                            if (inventoryLot == null)
                            {
                                inventoryLot = new InventoryLot(VENDOR_NAME_UTAC, LOCATION_TYPE_PRE_TEST );
                                m_preTestDataMap.put( partNumber + lotNumber + fabLotNumber, inventoryLot);
                            }
                            int quantity = 0;
                            if (inventoryLot.getQtyIn() != null)
                            {
                                try
                                {
                                    quantity = Integer.parseInt(inventoryLot.getQtyIn());
                                }
                                catch (NumberFormatException ignore) {
                                }
                                try
                                {
                                    quantity += Integer.parseInt(wipStatus.getDieQtyIn());
                                }
                                catch (NumberFormatException nfe) {
                                }
                            }
                            else
                            {
                                try
                                {
                                    quantity = Integer.parseInt(wipStatus.getDieQtyIn());
                                }
                                catch (NumberFormatException ignore) {
                                }
                            }

                            if ( quantity > 0 )
                            {
                                inventoryLot.setLotNumber( lotNumber );
                                inventoryLot.setPartNumber( partNumber );
                                inventoryLot.setStatus( lotStatus );
                                inventoryLot.setFabLotNumber( fabLotNumber );
                                inventoryLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                                inventoryLot.setStage( wipStatus.getStage() );
                                inventoryLot.setDateIn( wipStatus.getLotStartDate() );
                                if ( wipStatus.getExpectedDateOut() != null && wipStatus.getExpectedDateOut().length() > 8 )
                                {
                                     inventoryLot.setExpectedDate(StringUtils.formatDate(wipStatus.getExpectedDateOut(), "dd-MMM-yyy hh:mm:ss", "MM/dd/yyyy" ));
                                }
                                inventoryLot.setQtyIn( quantity +"");
                                inventoryLot.setHoldReason( wipStatus.getHoldReason() );
                                inventoryLot.setDateCode( wipStatus.getDateCode() );
                            }

                        }
                   }
                     //TEST // EOL
                    if (wipStatus.getProArea() != null &&  "EOL".equalsIgnoreCase(wipStatus.getProArea() ) )
                    {
                         log( "In Test EOL" + lotNumber );

                        inventoryLot = (InventoryLot) m_eolDataMap.get( partNumber + lotNumber + fabLotNumber);

                        if (inventoryLot == null)
                        {
                            inventoryLot = new InventoryLot(VENDOR_NAME_UTAC, LOCATION_TYPE_EOL );
                            m_eolDataMap.put( partNumber + lotNumber + fabLotNumber, inventoryLot);
                        }

                        int quantity = 0;
                        if (inventoryLot.getQtyIn() != null)
                        {
                            try
                            {
                                quantity = Integer.parseInt(inventoryLot.getQtyIn());
                            }
                            catch (NumberFormatException ignore) {
                            }
                            try
                            {
                                quantity += Integer.parseInt(wipStatus.getDieQtyIn());
                            }
                            catch (NumberFormatException nfe) {
                            }
                        }
                        else
                        {
                            try
                            {
                                quantity = Integer.parseInt(wipStatus.getDieQtyIn());
                            }
                            catch (NumberFormatException ignore) {
                            }
                        }
                        if ( quantity > 0 )
                        {
                            inventoryLot.setPartNumber(partNumber);
                            inventoryLot.setLotNumber(lotNumber);
                            inventoryLot.setQtyIn(quantity + "");
                            inventoryLot.setDateIn(wipStatus.getLotStartDate());
                            if ( wipStatus.getExpectedDateOut() != null && wipStatus.getExpectedDateOut().length() > 8 )
                            {
                                 inventoryLot.setExpectedDate(StringUtils.formatDate(wipStatus.getExpectedDateOut(), "dd-MMM-yyy hh:mm:ss", "MM/dd/yyyy" ));
                            }
                            inventoryLot.setFabLotNumber(fabLotNumber);
                            inventoryLot.setStatus(lotStatus);
                            inventoryLot.setHoldReason( wipStatus.getHoldReason() );
                            inventoryLot.setCategory(LOT_CATEGORY_TYPE_PROD );
                            inventoryLot.setStage( wipStatus.getStage() );
                            inventoryLot.setDateCode( wipStatus.getDateCode() );
                        }
                   }

                    // FG
                    if( wipStatus.getProArea() != null && "PTC".equalsIgnoreCase(wipStatus.getProArea() ) )
                    {
                        log( "In FG " + lotNumber );

                        inventoryLot = (InventoryLot) m_fgDataMap.get( partNumber + lotNumber + fabLotNumber);

                        if (inventoryLot == null)
                        {
                            inventoryLot = new InventoryLot(VENDOR_NAME_UTAC, LOCATION_TYPE_FG );
                            m_fgDataMap.put( partNumber + lotNumber + fabLotNumber, inventoryLot);
                        }
                        int quantity = 0;
                        if (inventoryLot.getQtyIn() != null)
                        {
                            try
                            {
                                quantity = Integer.parseInt(inventoryLot.getQtyIn());
                            }
                            catch (NumberFormatException ignore) {
                            }
                            try
                            {
                                quantity += Integer.parseInt(wipStatus.getDieQtyIn());
                            }
                            catch (NumberFormatException nfe) {
                            }
                        }
                        else
                        {
                            try
                            {
                                quantity = Integer.parseInt(wipStatus.getDieQtyIn());
                            }
                            catch (NumberFormatException ignore) {
                            }
                        }

                        if ( quantity > 0 )
                        {
                            inventoryLot.setLotNumber( lotNumber );
                            inventoryLot.setPartNumber( partNumber );
                            inventoryLot.setStatus( lotStatus );
                            inventoryLot.setFabLotNumber( fabLotNumber );
                            inventoryLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                            inventoryLot.setStage( wipStatus.getStage() );
                            inventoryLot.setDateIn( wipStatus.getLotStartDate() );
                            inventoryLot.setQtyIn( quantity +"");
                            inventoryLot.setHoldReason( wipStatus.getHoldReason() );
                            inventoryLot.setDateCode( wipStatus.getDateCode() );
                        }
                   }
                }
            }
        }
        catch( Exception e)
        {
            System.out.println("ERROR!! ERROR!! While parsing the UTAC Assy & Test Wip Data Details........" + e );
            e.printStackTrace();
            throw e;
        }
    }


    private void getShippingDetails(ArrayList shippingDataList) throws Exception
    {
       if ( shippingDataList == null || shippingDataList.size() == 0 )
       {
            return;
       }
       UTACShipStatus shipStatus  = null;
       String partNumber           = null;
       String lotNumber            = null;
       ShippedLot shippedLot       = null;
       String fabLotNumber         = null;
       String nextLocation         = null;
       try
       {
           Iterator iterator = shippingDataList.iterator();

           while ( iterator.hasNext() )
           {
               shipStatus = (UTACShipStatus) iterator.next();

               lotNumber    = shipStatus.getVendorLotNo();
               partNumber   = shipStatus.getDeviceName();
               fabLotNumber = shipStatus.getCustLotNo();
               nextLocation = shipStatus.getNextLocation();
               String shipDate = shipStatus.getShipDate();
               String dropShipNo = shipStatus.getPoNumber();
               //FG SHIP
               if ( shipStatus.getDateCode() != null )
               {
                   log("In FG Shippping " + lotNumber );
                   shippedLot = ( ShippedLot ) m_fgShipDataMap.get ( partNumber + lotNumber + fabLotNumber + nextLocation + shipDate + dropShipNo );

                   if ( shippedLot == null )
                   {
                        shippedLot = new ShippedLot(VENDOR_NAME_UTAC, LOCATION_TYPE_FINISHED_GOODS);
                        m_fgShipDataMap.put( partNumber + lotNumber + fabLotNumber + nextLocation + shipDate + dropShipNo, shippedLot );
                   }

                   int quantity = 0;
                   if ( shippedLot.getShipQty() != null )
                   {
                       try
                       {
                           quantity = Integer.parseInt( shippedLot.getShipQty() );
                       }
                       catch ( NumberFormatException ignore )
                       {
                           quantity = 0;
                       }
                       try
                       {
                           quantity += Integer.parseInt( shipStatus.getShipQty() );
                       }
                       catch ( NumberFormatException ignore )
                       {
                           quantity = 0;
                       }
                   }
                   else
                   {
                       try
                       {
                           quantity = Integer.parseInt( shipStatus.getShipQty() );
                       }
                       catch ( NumberFormatException ignore )
                       {
                           quantity = 0;
                       }
                   }

                   if ( quantity > 0 )
                   {
                       shippedLot.setLotNumber( lotNumber );
                       shippedLot.setPartNumber( partNumber );
                       shippedLot.setShipDate( shipDate );
                       shippedLot.setShipQty( quantity + "" );
                       shippedLot.setShippingDoc( dropShipNo );
                       shippedLot.setNextLocation( nextLocation );
                       shippedLot.setInvoiceNumber( shipStatus.getInvoiceNo() );
                       shippedLot.setFabLotNumber( fabLotNumber );
                       shippedLot.setMawb( shipStatus.getMawbNo() );
                       shippedLot.setHawb( shipStatus.getHawbNo() );
                       shippedLot.setEtd( shipStatus.getEtd() );
                       shippedLot.setEta( shipStatus.getEta() );
                       shippedLot.setFlightNumber( shipStatus.getFlightNo() );
                       shippedLot.setProcessType( LOCATION_TYPE_FG );

                   }
               }
               //CP SHIPPING
               else
               {
                      log("In CP Shippping " + lotNumber );
                   shippedLot = ( ShippedLot ) m_sortShipDataMap.get ( partNumber + fabLotNumber + nextLocation + shipDate );

                   if ( shippedLot == null )
                   {
                        shippedLot = new ShippedLot(VENDOR_NAME_UTAC, LOCATION_TYPE_SORT);
                        m_sortShipDataMap.put( partNumber + fabLotNumber + nextLocation + shipDate, shippedLot );
                   }

                   int quantity = 0;
                   if ( shippedLot.getShipQty() != null )
                   {
                       try
                       {
                           quantity = Integer.parseInt( shippedLot.getShipQty() );
                       }
                       catch ( NumberFormatException ignore )
                       {
                           quantity = 0;
                       }
                       try
                       {
                           quantity += Integer.parseInt( shipStatus.getShipQty() );
                       }
                       catch ( NumberFormatException ignore )
                       {
                           quantity = 0;
                       }
                   }
                   else
                   {
                       try
                       {
                           quantity = Integer.parseInt( shipStatus.getShipQty() );
                       }
                       catch ( NumberFormatException ignore )
                       {
                           quantity = 0;
                       }
                   }

                   if ( quantity > 0 )
                   {
                       shippedLot.setLotNumber( fabLotNumber );
                       shippedLot.setPartNumber( partNumber );
                       shippedLot.setShipDate( shipDate );
                       shippedLot.setShipQty( quantity + "" );
                       shippedLot.setNextLocation( nextLocation );
                       shippedLot.setInvoiceNumber( shipStatus.getInvoiceNo() );
                       shippedLot.setFabLotNumber( fabLotNumber );
                       shippedLot.setMawb( shipStatus.getMawbNo() );
                       shippedLot.setHawb( shipStatus.getHawbNo() );
                       shippedLot.setEtd( shipStatus.getEtd() );
                       shippedLot.setEta( shipStatus.getEta() );
                       shippedLot.setFlightNumber( shipStatus.getFlightNo() );
                       shippedLot.setProcessType( LOCATION_TYPE_SORT );

                   }
               }
           }
        }
        catch(Exception e )
        {
            e.printStackTrace();
            log("Exception while geting ASECL Shipping inforamtion" + e);
            throw  e;
        }
    }
   private static void log( String message )
    {

        if ( message == null ) return;

        if ( m_parserLogger != null )
        {
            synchronized ( m_parserLogger )
            {
                m_parserLogger.logDebug( message + LINE_SEPARATOR );
            }
        }
        else
        {
            System.out.println( message );
        }
    }
}
